<script lang="ts" setup name="LoginCallback">
import LoginHeader from './components/login-header.vue'
import LoginFooter from './components/login-footer.vue'
import CallbackBind from './components/callback-bind.vue'
import CallbackPatch from './components/callback-patch.vue'
import useStore from '@/store'
import { ref } from 'vue';
import Message from '@/components/message'
import { useRouter } from 'vue-router'
const {user} =useStore()
const router=useRouter()
const hasAccount=ref(true)

//1,回跳组件初始化的时候根据QQ的接口获取openid
//2.,根据openId去自己后台尝试进行登录
//3.如果成功，就代表已注册已绑定，记录返回的用户信息，跳转到首页或者来源页面
//api:
//QC.api('get_use_info')
//QC.Login.signout()退出QQ
//QC.Login.check() 检测是否登录
// QC.Login.getMe(function(openId){
// console.log(openId);
// })
// console.log(QC.Login.check());
const isLogin=QC.Login.check()
// console.log(isLogin);
if(isLogin){
    QC.Login.getMe( async(openId)=>{
        // 异步user.qqLogin(openId)
    await  user.qqLogin(openId)
     Message.success('登录成功')
     router.push('/')
    })
}

</script>

<template>
  <LoginHeader></LoginHeader>
  <section class="container">
    <nav class="tab">
      <a href="javascript:;" @click="hasAccount=true" :class="{active:hasAccount}">
        <i class="iconfont icon-bind" />
        <span>已有小兔鲜账号，请绑定手机</span>
      </a>
      <a href="javascript:;" @click="hasAccount=false" :class="{active:!hasAccount}">
        <i class="iconfont icon-edit" />
        <span>没有小兔鲜账号，请完善资料</span>
      </a>
    </nav>
    <div class="tab-content" v-if="hasAccount">
    <CallbackBind></CallbackBind>
    </div>
    <div class="tab-content" v-else>
    <CallbackPatch></CallbackPatch>
    </div>
  </section>
  <LoginFooter></LoginFooter>
</template>

<style scoped lang="less">
.container {
  padding: 25px 0;
}
.tab {
  background: #fff;
  height: 80px;
  padding-top: 40px;
  font-size: 18px;
  text-align: center;
  a {
    color: #666;
    display: inline-block;
    width: 350px;
    line-height: 40px;
    border-bottom: 2px solid #e4e4e4;
    i {
      font-size: 22px;
      vertical-align: middle;
    }
    span {
      vertical-align: middle;
      margin-left: 4px;
    }
    &.active {
      color: @xtxColor;
      border-color: @xtxColor;
    }
  }
}
.tab-content {
  min-height: 600px;
  background: #fff;
}
</style>
